package com.example.oss.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应结果
 */

@Data
@NoArgsConstructor
public class Result {
    private int code;
    private String msg;
    private String token;

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(ResultEnum resultEnum, String token) {
        this.msg = resultEnum.msg();
        this.token = token;
        this.code = 0;
    }

    public static Result success(ResultEnum resultEnum, String token) {
        return new Result(resultEnum, token);
    }

    public static Result failure(ResultEnum resultEnum) {
        return new Result(1, resultEnum.msg());
    }

    public static Result success(ResultEnum resultEnum) {
        return new Result(0, resultEnum.msg());
    }

    public static Result failure(String msg) {
        return new Result(0, msg);
    }

}